class Share {
  constructor() {
    const share = $('.use-share')
    const that = this
    if (share.get(0)) {
      const h = `<a type="weibo"><i class="iconfont">&#xe663;</i></a><a type="shareqq"><i class="iconfont">&#xe6b4;</i></a><a type="qzshare"><i class="iconfont">&#xe62a;</i></a><a type="tieba"><i class="iconfont">&#xe6d7;</i></a>`
      const title = this.get(share.data('title')) + '（分享自 @99496动漫网 #9站##99496动漫#）'
      const desc = this.get(share.data('desc'))
      const name = this.get(share.data('name'))
      const pic = this.get(share.data('pic'))
      share.html(h)
      share.find('a').click(function() {
        const type = $(this).attr('type')
        that.share(type, title, desc, name, pic)
      })
    }
  }

  share(type, title, desc, name, pic) {
    const url = window.location.href
    const site = {
      weibo: `https://service.weibo.com/share/share.php?appkey=111884427&url=${url}&title=${title}&pic=${pic}`,
      shareqq: `https://connect.qq.com/widget/shareqq/index.html?url=${url}&title=${title}&desc=&summary=${desc}&pics=${pic}&site=${name}`,
      qzshare: `https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${url}&title=${title}&desc=&summary=${desc}&pics=${pic}&site=${name}`,
      tieba: `http://tieba.baidu.com/f/commit/share/openShareApi?title=${title}&url=${url}&uid=726865&to=tieba&type=text&relateUid=&pic=${pic}&key=&sign=on&desc=&comment=&red_tag=a1164198419`
    }
    window.open(site[type], '_blank', 'width=770, height=620')
  }

  get(d) {
    return encodeURIComponent(d)
  }
}

export default Share
